// createSlice: 用于创建状态切片
import { createSlice } from "@reduxjs/toolkit";

// actions: 对象类型, 用于存储 action creator 函数, 函数名字和 reducers 配置选项中 reducer 函数的名字相对应
const { actions, reducer: UserInfo } = createSlice({
    name: "userinfo",
    initialState: {token:null},
    reducers: {
        // 添加任务
        editToken(state, action) {
            console.log(action)
            if (action.payload.type==='add'){
                state.token=action.payload.token
            }else {
                state.token=null
            }
            localStorage.setItem('JLYTOKEN',state.token)
            console.log(state.token)
        },
    },
});
// 导出 action creator 函数, 供组件使用
export const { editToken } = actions;
// 导出 reducer 函数, 因为在后续的代码中还是要合并 reducer 函数
export default UserInfo;
